package com.lihao.sam.controller;

import com.lihao.sam.entity.LeaveSchool;
import com.lihao.sam.service.intf.LeaveSchoolService;
import com.lihao.sam.vo.PageVo;
import com.lihao.sam.vo.R;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;
import java.util.Map;

/**
 * *  作者:陈国强
 * *  日期:2022/11/22 17:58
 * *  文件描述:
 */
@RestController
@RequestMapping("/api/LeaveSchool/")
public class LeaveSchoolController {
    @Resource
    private LeaveSchoolService service;
    @PostMapping("add.do")
    public R add(LeaveSchool chaNorm){
        return service.add(chaNorm);
    }
    @PostMapping("update.do")
    public R update(LeaveSchool school){
        return service.update(school);
    }
    @PostMapping("delete.do")
    public R delete(int id, HttpSession session){
        return service.delete(id);
    }
    @GetMapping("page.do")
    public PageVo page(String stuId, String name,String address,int page, int limit){
        return service.queryPage(stuId, name,address,page, limit);
    }

    //上传Excel文件
    @PostMapping("upload.do")
    public R upload(MultipartFile file) throws IOException {
        return service.importData(file);
    }
    //下载Excel文件
    @GetMapping("download.do")
    public void downLoad(HttpServletResponse response) throws IOException {
        service.exportData(response);
    }
//    @RequestMapping("page.do")
//    public PageVo page(@RequestParam Map<String,Object> map){
//        //return service.queryPage(stuId, name,address,page, limit);
//        System.out.println("map = " + map);
//        String stuId = map.get("stuId") + "";
//        String name = map.get("name") + "";
//        String address = map.get("address") + "";
//        Integer page = Integer.valueOf(map.get("page") + "");
//        Integer limit = Integer.valueOf(map.get("limit") + "");
//        System.out.println("stuId = " + stuId);
//        System.out.println("name = " + name);
//        System.out.println("address = " + address);
//        return service.queryPage(stuId, name, address, page, limit);
//    }

    //图表
    @GetMapping("roletj.do")
    public R tj(){
        return service.selectLeaveSchool();
    }
}
